package com.taiyuan.zfmvp.Dynamic.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.taiyuan.zfmvp.Dynamic.model.TestIdCard;
import com.taiyuan.zfmvp.Dynamic.service.TestIdCardService;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @param request
 * @Author: zhoufang@si-tech.com.cn
 * @Descriiption:
 * @Date 2022/2/2
 * @return
 */
@RequestMapping("/id")
@RestController
public class IdCardController {

    @Resource
    private TestIdCardService testIdCardService;

    private static final Logger logger = LoggerFactory.getLogger(IdCardController.class.getName());

    private static final Logger sqllogger = LoggerFactory.getLogger("sqllog");

    private static final Logger errlogger = LoggerFactory.getLogger("errlog");

    /**
     * @Author zhoufang@si-tech.com.cn
     * @Description
     * @Date 2022/2/2
     * @Param
     * @Return
     */
    @PostMapping("/getById")
    @ResponseBody
    public TestIdCard getById(@RequestBody Map<String, Object> inMap) {

        try {
           TestIdCard testIdCard = testIdCardService.getIdCardInfo((Integer)inMap.get("id"));
            return testIdCard;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * @Author zhoufang@si-tech.com.cn
     * @Description  验证 &符号编码   &：%26
     * @Date 2022/2/12
     * @Param
     * @Return
     */
    @GetMapping("/getByUrl")
    @ResponseBody
    public TestIdCard getById(@RequestParam String a,@RequestParam String b) {

        try {
            //TestIdCard testIdCard = testIdCardService.getIdCardInfo((Integer)inMap.get("id"));
           // return testIdCard;
            System.out.println(a+"--------"+b);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


    /**
     * @Author zhoufang@si-tech.com.cn
     * @Description  列表分页集成 pageHelper
     * @Date 2022/2/12
     * @Param
     * @Return
     */
    @PostMapping("/getInfoList")
    @ResponseBody
    public JSONObject getInfoList(@RequestBody Map<String, String> inMap) {
        logger.debug("进入方法");
        sqllogger.debug("sql");
        try {
            Integer pageNo = inMap.get("page_num") == null?1:Integer.valueOf(inMap.get("page_num"));
            Integer pageSize = inMap.get("page_size") == null?10:Integer.valueOf(inMap.get("page_size"));
            PageHelper.startPage(pageNo,pageSize);
            PageInfo<TestIdCard> pageInfo = new PageInfo<>(testIdCardService.qryCardLst(inMap));
            return JSONObject.fromObject(pageInfo);
        } catch (Exception e) {
            errlogger.debug(e.getMessage());
            e.printStackTrace();
        }
        return null;
    }
}
